#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int key = 7;
	int left = 0;
	int right = sizeof(arr)/sizeof(arr[0]);
	printf("%d",find(arr, key, left, right));
	return 0;
}

int find(int arr[], int key, int left, int right)
{
	int mid = 0;
	int find = 0;
	while (left <= right)
	{
		mid = (left + right) / 2;
		if (arr[mid] < key)
		{
			left = mid+1;
		}
		else if(arr[mid] > key)
		{
			right = mid-1;
		}
		else
		{
			find = 1;
			break;
		}

	}
	if (find == 1)
		return mid;
	else
		return -1;
}

